package com.edge.pbx.view.xover;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

import com.edge.pbx.view.PbxCircleSeekBar;
import com.edge.pbxdsp.R;


/**
 * Copyright (C), 深圳市东乘电子科技有限公司
 * Carate By YangZhong
 */
public class XoverFreqSeekBar extends PbxCircleSeekBar {
    private RectF mInputRect;
    private Paint mPaint;
    private Drawable mDrawableSlopeBg;
    public XoverFreqSeekBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.WHITE);
        mInputRect = new RectF();
        mDrawableSlopeBg = context.getDrawable(R.drawable.pbx_xover_slope_bg);
    }

    Rect rett  = new Rect();
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        final int width = right - left;
        final int height = bottom - top;
        int baseL = (width - mCircleBgSize)/2;

        int frameWidth = (int) (mCircleBgSize*0.42f);

        Rect drawableTitleBounds = mDrawableTitle.getBounds();

        mInputRect.left = baseL + ( mCircleBgSize - frameWidth)/2;
        mInputRect.right = mInputRect.left + frameWidth;
        int offset = 0;//(int) (drawableTitleBounds.height()*0.1f);
        mInputRect.top = drawableTitleBounds.top - offset;
        mInputRect.bottom = drawableTitleBounds.bottom + offset;



        int w = (int) (mCircleBgSize*0.84f);
        int h = (int) (mCircleBgSize*0.16f);
        int l = (width-w)/2;
        int t = (int) (height * 0.637f)-h/2;
        rett.set( l,t , l + w, t +h);
        mDrawableSlopeBg.setBounds(l,t,l+w,t+h);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        Paint p = new Paint();
        p.setColor(Color.GREEN);
//        canvas.drawRect(rett,p);
        mDrawableSlopeBg.draw(canvas);
        super.dispatchDraw(canvas);

    }

    public RectF getInputRect() {
        return mInputRect;
    }


}
